#!/usr/bin/env python
from xml.etree.ElementTree import SubElement

def add_subelement(xml_node, element_name, element_text, **args):
    def args_value_to_str(args):
        for arg_name in args.keys():
            args[arg_name] = str(args[arg_name])
    args_value_to_str(args)
    element = SubElement(xml_node, element_name, args)
    for arg_name in args.keys():
        element.attrib[arg_name] = args[arg_name]
    if element_text != None or element.text != None:
		if isinstance(element_text, int):
			element_text = str(element_text)
		element.text = element_text
    return element

def save_object(object, xml_node):
    attribList = [attrib for attrib in dir(object) if not callable(getattr(object, attrib))]
    for attrib in attribList:
        add_subelement(xml_node, attrib, getattr(object, attrib))